<template>
  <div>
      <div class="login-bg">
        <div class="login">
          <div class="login-li login-li1 login-li2">
            <img src="../assets/img/logo1.png">
          </div>
          <div class="login-li">
            <div class="login-title">公司ID：</div>
            <div class="login-input">
              <input type="text" name="" value="" v-model="loginForm.company_id ">
            </div>
          </div>
          <div class="login-li">
            <div class="login-title">账号：</div>
            <div class="login-input">
              <input type="text" name="" value="" v-model="loginForm.account">
            </div>
          </div>
          <div class="login-li">
            <div class="login-title">密码：</div>
            <div class="login-input">
              <input name="" type="Password" value="" v-model="loginForm.password">
            </div>
          </div>

          <div class="login-li login-li1">
            忘记密码？<span>找回密码</span>
          </div>
          <div class="login-li login-li1">
            <button @click="onSubmit()" style="width: 100%;">登录</button>
            <!--<button>注册</button>-->
          </div>
        </div>
      </div>
    <div v-show="submitShow">
      <Modal :ModalClose="Closesubmit" :message="message" :pushTo="pushTo"></Modal>
    </div>
  </div>
  <!--<div></div>-->
</template>
<script type="text/babel">
  import axios from 'axios'
  import Modal from './modal.vue';
  export default {
    name: 'Login',
    components: {
      Modal
    },
    data() {
      return {
        // account: '',
        // password1: '',
        // company_id: 2,
        submitShow: false,
        message: '',
        pushTo: '',
        loginForm: {
          account: '',
          password: '',
          company_id: '',
        },
      }
    },
    methods: {
      headMenu(){
        this.$http.get('/index/menu',{
        })
        .then(res => {
          console.log(res.data);
          this.$store.state.menus = eval(res.data);
        })
        .catch(err => {
          console.log(err);
        });
      },
      onSubmit() {
        let that = this;
        that.$http.post('/login', that.loginForm)
          .then(function (response) {
            // console.log(response);
            if (response.data.status === 1) {
              localStorage.token = response.data.data.token;
              localStorage.userinfo = JSON.stringify(response.data.data);
              console.log('---------------');
              console.log(response);
              console.log(localStorage.userinfo);
              console.log(localStorage.token);
              console.log('---------------');
              that.headMenu();
              // console.log(localStorage.token);
              // this.$store.state.loginFrom = that.loginForm;
              that.submitShow = true;
              // that.$router.push({name: 'Index'});
              that.message = '登录成功';
              that.pushTo = 'Index'
              // alert(localStorage.token)

               //登录成功后2秒跳转
               setTimeout(()=>{
                 that.$router.push({name:"Index"});
               },1000);
            } else {
              that.submitShow = true;
              that.message = response.data.msg;
              that.pushTo = 'Login'
            }
          })
          .catch(function (error) {
            console.log(error);
          });
      },
      Closesubmit() {
        this.submitShow = false
      }
    },
    created() {
    },
    mounted(){
      // if( localStorage.token.length > 1){
      //   // alert('a')
      //   this.$router.push({name: 'Index'});
      // }
    }
  }
</script>
<style scoped>
  .login-li span {
    float: right;
  }
  .login-li2 {
    text-align: center;
    font-size: 3em;
    margin-top: 0 !important;
  }
  .login-li button {
    width: 49%;
    background: #69bf12;
    color: #fff;
    height: 40px;
    line-height: 40px;
    border: none;
    border-radius: 5px;
    cursor:pointer;
  }
  /*.login-li button:nth-child(1) {*/
  /*}*/
  .login-li1 {
    background: none !important;
    color: #ffffff;
  }
  .login-title {
    width: 25%;
    float: left;
    line-height: 40px;
    font-size: 1.1em;
    color: #fff;
    text-align: center;
  }
  .login-input {
    width: 75%;
    float: left;
  }
  .login-input input {
    width: 95%;
    float: left;
    color: #fff;
    background: none;
    border: none;
    padding-left: 5%;
    line-height: 40px;
  }
  .login-li1 img {
    width: 7rem;
  }
  .login-li {
    margin-top: 30px;
    width: 100%;
    border-radius: 5px;
    overflow: hidden;
    background: rgba(255, 255, 255, .2);
    float: left;
  }
  .login {
    width: 300px;
    height: 376px;
    border-radius: 10px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -188px;
    margin-left: -150px;
    z-index: 99;
    cursor:pointer;
  }
  .login-bg {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: url(../assets/img/b-bg.jpg) no-repeat;
    background-size: 100% 100%;
  }
  .logo img{
    width: 73px;
  }
</style>
